/*
 * @Description: 编辑单位弹窗
 * @Author: Rfan
 * @Date: 2022-01-07 14:54:11
 * @LastEditTime: 2022-05-26 15:46:09
 */

import { FC } from 'react';
import { Button, Form, Modal } from 'antd';
import AddUnitForm from './common/AddUnitForm';
import type { ICommonDialog } from '@/interfaces/global';

interface EditUnitDialogProps extends ICommonDialog {
  data: any;
}

const EditUnitDialog: FC<EditUnitDialogProps> = (props) => {
  console.log('add unit dialog', props.visible);
  const { visible, data, onClose } = props;
  const [form] = Form.useForm();

  const submitFunc = () => {
    form.submit();
  };

  const onCancel = () => {
    form.resetFields();
    onClose();
  };

  return (
    <Modal
      destroyOnClose
      title="编辑单位"
      visible={visible}
      onCancel={onCancel}
      footer={[
        <Button key="back" onClick={onCancel}>
          取消
        </Button>,
        <Button key="submit" type="primary" onClick={submitFunc}>
          保存
        </Button>
      ]}
    >
      <AddUnitForm
        form={form}
        data={data}
        visible={visible}
        closeDialog={() => {
          onCancel();
        }}
      />
    </Modal>
  );
};

export default EditUnitDialog;
